/*
 * @Description:
 * @version:
 * @Author: 171
 * @Date: 2022-08-31 10:29:54
 * @LastEditors: 171
 * @LastEditTime: 2022-09-15 18:25:21
 */
import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
// import vueJsx from "@vitejs/plugin-vue-jsx";

import { visualizer } from "rollup-plugin-visualizer";
import { VitePWA } from "vite-plugin-pwa";

const pwa = VitePWA({
  workbox: {
    cacheId: "MyCache", //缓存名称
    runtimeCaching: [
      {
        urlPattern: /.*\.js.*/, //缓存文件
        handler: "StaleWhileRevalidate", //重新验证时失效
        options: {
          cacheName: "Cache-js", //缓存js，名称
          expiration: {
            maxEntries: 30, //缓存文件数量 LRU算法
            maxAgeSeconds: 30 * 24 * 60 * 60, //缓存有效期
          },
        },
      },
    ],
  },
});

export default defineConfig({
  plugins: [
    vue(),
    pwa,
    visualizer({
      open: true,
    }),
  ],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  build: {
    // Vite 配置优化
    chunkSizeWarningLimit: 2000,
    cssCodeSplit: true, //css 拆分
    sourcemap: false, //不生成sourcemap
    minify: false, //是否禁用最小化混淆，esbuild打包速度最快，terser打包体积最小。
    assetsInlineLimit: 5000, //小于该值 图片将打包成Base64
  },
  optimizeDeps: {
    include: ["@kangc/v-md-editor/lib/theme/vuepress.js"],
  },
  define: {
    'process.env': {
      VUE_APP_URL: "http://localhost:3100"
    }
  }
});
